import {FormItemRule} from "naive-ui"

//表单校验规则
const checklabelwidth = (rule: FormItemRule, value: string) => {
    const regx = /^[1-9]\d*$/
    if (!value) {
        return true
    } else if (!regx.test(value)) {
        return new Error("请输入正整数")
    } else if (value.length > 10) {
        return new Error("最多10位字符")
    } else {
        return true
    }
}

const checknum = (rule: FormItemRule, value: string) => {
    const regx = /^[1-9]\d{0,9}$/
    if (!value) {
        return true
    } else if (!regx.test(value)) {
        return new Error("请输入正整数")
    } else {
        return true
    }
}

const labelformitem = {
    span: 24,
    label: "标题",
    key: "label",
    default: "",
    type: "input",
    placeholder: "请输入标题",
    rules: [
        {required: true, message: "请输入标题", triggher: ["change", "blur"],},
        {max: 200, min: 2, message: "请输入2-200为字符", triggher: ["change", "blur"],},
    ],
}
const spanformitem = {
    span: 24,
    label: "宽度",
    key: "span",
    default: "",
    type: "select",
    placeholder: "请输入宽度",
    rules: [
        {required: true, message: "请选择宽度", triggher: ["change", "blur"],},
    ],
    options: [
        {label: "1", value: "1"},
        {label: "2", value: "2"},
        {label: "3", value: "3"},
        {label: "4", value: "4"},
        {label: "5", value: "5"},
        {label: "6", value: "6"},
        {label: "7", value: "7"},
        {label: "8", value: "8"},
        {label: "9", value: "9"},
        {label: "10", value: "10"},
        {label: "11", value: "11"},
        {label: "12", value: "12"},
        {label: "13", value: "13"},
        {label: "14", value: "14"},
        {label: "15", value: "15"},
        {label: "16", value: "16"},
        {label: "17", value: "17"},
        {label: "18", value: "18"},
        {label: "19", value: "19"},
        {label: "20", value: "20"},
        {label: "21", value: "21"},
        {label: "22", value: "22"},
        {label: "23", value: "23"},
        {label: "24", value: "24"},
    ],
}

const showformitem = {
    span: 24,
    label: "是否显示",
    key: "show",
    default: "",
    type: "switch",
    placeholder: "请选择是否显示",
    rules: [
        {required: true, message: "请选择是否显示", triggher: ["change", "blur"],},
    ],
}

const keyformitem = {
    span: 24,
    label: "表单key",
    key: "key",
    default: "",
    type: "input",
    placeholder: "请输入表单key",
    rules: [
        {required: true, message: "请输入表单key", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const defaultformitem = {
    span: 24,
    label: "默认值",
    key: "default",
    default: "",
    type: "input",
    placeholder: "请输入默认值",
    rules: [
        {required: true, message: "请输入默认值", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const placeholderformitem = {
    span: 24,
    label: "提示语",
    key: "placeholder",
    default: "",
    type: "input",
    placeholder: "请输入提示语",
    rules: [
        {required: true, message: "请输入提示语", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const inputtypeformitem = {
    span: 24,
    label: "input输入框的类型",
    key: "inputType",
    default: "",
    type: "select",
    placeholder: "请选择类型",
    rules: [
        {required: true, message: "请选择类型", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
    options: [
        {label: "文本", value: "text"},
        {label: "密码", value: "password"},
    ],
}

const clearableformitem = {
    span: 24,
    label: "是否能清除",
    key: "clearable",
    default: "",
    type: "switch",
    placeholder: "请选择是否能清除",
    rules: [
        {required: true, message: "请选择是否能清除", triggher: ["change", "blur"],},
    ],
}

const disabledformitem = {
    span: 24,
    label: "是否不可操作",
    key: "disabled",
    default: "",
    type: "switch",
    placeholder: "请选择是否不可操作",
    rules: [
        {required: true, message: "请选择是否不可操作", triggher: ["change", "blur"],},
    ],
}

const sizeformitem = {
    span: 24,
    label: "尺寸",
    key: "size",
    default: "small",
    type: "select",
    placeholder: "请选择尺寸",
    rules: [
        {required: true, message: "请选择尺寸", triggher: ["change", "blur"],},
    ],
    options: [
        {label: "小", value: "small",},
        {label: "中", value: "medium",},
        {label: "大", value: "large",},
    ],
}

const requiredformitem = {
    span: 24,
    label: "是否必填",
    key: "required",
    default: "",
    type: "switch",
    placeholder: "请选择是否必填",
    rules: [
        {required: true, message: "请选择是否必填", triggher: ["change", "blur"],},
    ],
}

const maxlengthformitem = {
    span: 24,
    label: "最大文本长度",
    key: "maxlength",
    default: "",
    type: "input",
    placeholder: "请输入最大文本长度",
    rules: [
        {required: true, message: "请输入最大文本长度", triggher: ["change", "blur"],},
        {validator: checknum, triggher: ["change", "blur"],}
    ],
}

const minlengthformitem = {
    span: 24,
    label: "最小文本长度",
    key: "minlength",
    default: "",
    type: "input",
    placeholder: "请输入最小文本长度",
    rules: [
        {required: true, message: "请输入最小文本长度", triggher: ["change", "blur"],},
        {validator: checknum, triggher: ["change", "blur"],}
    ],
}

const multipleformitem = {
    span: 24,
    label: "是否多选",
    key: "multiple",
    default: "",
    type: "switch",
    placeholder: "请选择是否多选",
    rules: [
        {required: true, message: "请选择是否多选", triggher: ["change", "blur"],},
    ],
}

const dateTypeformitem = {
    span: 24,
    label: "宽度",
    key: "dateType",
    default: "",
    type: "select",
    placeholder: "请输入宽度",
    rules: [
        {required: true, message: "请选择宽度", triggher: ["change", "blur"],},
    ],
    options: [
        {label: "日期", value: "date"},
        {label: "日期时间", value: "datetime"},
        {label: "日期范围", value: "daterange"},
        {label: "日期时间范围", value: "datetimerange"},
        {label: "月", value: "month"},
        {label: "月范围", value: "monthrange"},
        {label: "年", value: "year"},
        {label: "年范围", value: "yearrange"},
        {label: "季度", value: "quarter"},
        {label: "季度范围", value: "quarterrange"},
    ],
}

const roundformitem = {
    span: 24,
    label: "是否圆角",
    key: "round",
    default: "",
    type: "switch",
    placeholder: "请选择是否圆角",
    rules: [
        {required: true, message: "请选择是否圆角", triggher: ["change", "blur"],},
    ],
}

const valueFieldformitem = {
    span: 24,
    label: "value关键字",
    key: "valueField",
    default: "",
    type: "input",
    placeholder: "请输入value关键字",
    rules: [
        {required: true, message: "请输入value关键字", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const labelFieldformitem = {
    span: 24,
    label: "label关键字",
    key: "labelField",
    default: "",
    type: "input",
    placeholder: "请输入label关键字",
    rules: [
        {required: true, message: "请输入label关键字", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const childrenFieldformitem = {
    span: 24,
    label: "children关键字",
    key: "childrenField",
    default: "",
    type: "input",
    placeholder: "请输入children关键字",
    rules: [
        {required: true, message: "请输入children关键字", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}

const filterableformitem = {
    span: 24,
    label: "是否开启过滤",
    key: "filterable",
    default: "",
    type: "switch",
    placeholder: "请选择是否开启过滤",
    rules: [
        {required: true, message: "请选择是否开启过滤", triggher: ["change", "blur"],},
    ],
}

const rulesformitem = {
    span: 24,
    label: "自定义校验规则",
    key: "rules",
    default: "",
    type: "textarea",
    placeholder: "请输入自定义校验规则",
    rules: [
        {max: 2000, message: "最多2000个字符", trigger: ["change", "blur"]},
    ],
}

const pathformitem = {
    span: 24,
    label: "值路径path",
    key: "path",
    default: "",
    type: "input",
    placeholder: "请输入值路径path",
    rules: [
        {required: true, message: "请输入值路径path", triggher: ["change", "blur"],},
        {max: 200, message: "最多200个字符", trigger: ["change", "blur"]},
    ],
}


const listTypeformitem = {
    span: 24,
    label: "文件样式",
    key: "listType",
    default: "small",
    type: "checkbox",
    placeholder: "请选择文件样式",
    rules: [
        {required: true, message: "请选择文件样式", triggher: ["change", "blur"],},
    ],
    options: [
        {label: "文字", value: "text",},
        {label: "图片", value: "image",},
        {label: "卡片", value: "image-card",},
    ],
}


const directoryDndformitem = {
    span: 24,
    label: "是否支持拖拽",
    key: "directoryDnd",
    default: "",
    type: "switch",
    placeholder: "请选择是否支持拖拽",
    rules: [
        {required: true, message: "请选择是否支持拖拽", triggher: ["change", "blur"],},
    ],
}

const maxfilesformitem = {
    span: 24,
    label: "最大文件数量",
    key: "maxfiles",
    default: "",
    type: "input",
    placeholder: "请输入最大文件数量",
    rules: [
        {required: true, message: "请输入最大文件数量", triggher: ["change", "blur"],},
        {validator: checknum, triggher: ["change", "blur"],}
    ],
}
const cascadeformitem = {
    span: 24,
    label: "是否上下关联",
    key: "cascade",
    default: "",
    type: "switch",
    placeholder: "请选择是否上下关联",
    rules: [
        {required: true, message: "请选择是否上下关联", triggher: ["change", "blur"],},
    ],
}

const maxselectformitem = {
    span: 24,
    label: "最大选择数量",
    key: "maxselect",
    default: "",
    type: "input",
    placeholder: "请输入最大选择数量",
    rules: [
        {required: true, message: "请输入最大选择数量", triggher: ["change", "blur"],},
        {validator: checknum, triggher: ["change", "blur"],}
    ],
}

const slotformitem = {
    span: 24,
    label: "插槽内容",
    key: "slot",
    default: "",
    type: "input",
    placeholder: "请输入插槽内容",
    rules: [
        {required: true, message: "请输入插槽内容", triggher: ["change", "blur"],},
        {max: 2000, message: "最多2000个字符", trigger: ["change", "blur"]},
    ],
}

const classformitem = {
    span: 24,
    label: "自定义class",
    key: "classlist",
    type: "textarea",
    default: "",
    placeholder: "请输入自定义class",
    rules: [
        {max: 2000, message: "最多2000个字符", trigger: ["change", "blur"]},
    ],
}
const styleformitem = {
    span: 24,
    label: "自定义style",
    key: "classlist",
    type: "textarea",
    default: "",
    placeholder: "请输入自定义style",
    rules: [
        {max: 2000, message: "最多2000个字符", trigger: ["change", "blur"]},
    ],
}


export default {
    "row": [
        classformitem,styleformitem,
        spanformitem,
        showformitem,
    ],
    "col": [
        classformitem,styleformitem,
        spanformitem,
        showformitem,
    ],
    "card": [
        classformitem,styleformitem,
        spanformitem,
        showformitem,
        labelformitem,
    ],
    "button": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem, roundformitem,
        maxlengthformitem, minlengthformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "input": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem, roundformitem,
        maxlengthformitem, minlengthformitem,
        requiredformitem, sizeformitem,
        disabledformitem, inputtypeformitem,
        placeholderformitem, defaultformitem,
    ],
    "select": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "cascader": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "checkbox": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "picker": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
        dateTypeformitem,
    ],
    "radio": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "switch": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "textarea": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "slot": [],
    "imgupload": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "fileupload": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
    "richtext": [
        classformitem,styleformitem,
        labelformitem,
        spanformitem,
        showformitem, keyformitem,
        pathformitem, rulesformitem,
        clearableformitem,
        requiredformitem, sizeformitem,
        disabledformitem,
        placeholderformitem, defaultformitem,
    ],
}
